# $Id$
# Maintainer : Tom Gundersen <teg@jklm.no>
# Maintainer : Ionut Biru <ibiru@archlinux.org>
# Contributor: Gabriel Martinez < reitaka at gmail dot com >

pkgname=libimobiledevice
pkgver=1.2.0
pkgrel=6
pkgdesc="Library that talks the protocols to support iPhone and iPod Touch devices on Linux"
url="http://libimobiledevice.org/"
arch=('i686' 'x86_64')
license=('GPL2' 'LGPL2.1')
depends=('libusbmuxd' 'usbmuxd' 'gnutls')
makedepends=('python2' 'cython2' 'python' 'cython' 'libplist' 'autoconf-archive')
source=(http://libimobiledevice.org/downloads/$pkgname-$pkgver.tar.bz2
        0001-Fix-installation_proxy-when-using-GnuTLS-instead-of-.patch
        CVE-2016-5104.patch
        0001-Add-new-function-to-get-the-underlying-file-descript.patch
        0001-Updated-gnutls-certificate-callback-to-new-API-backw.patch
        0001-idevice-Update-GnuTLS-code-to-support-iOS-10.patch
        0001-userpref-GnuTLS-Fix-pairing-record-generation-and-im.patch)
sha256sums=('786b0de0875053bf61b5531a86ae8119e320edab724fc62fe2150cc931f11037'
            '9fb1523276f9ab4273f0065728c52792ec6c99c09d587c28175c748175106a09'
            '30d8032244859adc85f11df00a5b3adb017160821ddf4b22a8528f9b104c0951'
            'a4a1844dfedc933cb998afbbe4b2066d8bcedf8d305990715160b957f754922c'
            '9e03d66e15ad036e7e3b8639b07788a0c1959016444766ad63f708e722bd516c'
            '173291a36ea08226c221643580c007f44e430867f345d8106395cce0f52a38c5'
            '7d3c5a89ce6611c219d80255a1cce4a02de4ca00fb58c32e87733d9a0e20c4ce')

prepare() {
  cd "$pkgname-$pkgver"
  patch -Np1 -i ../0001-Fix-installation_proxy-when-using-GnuTLS-instead-of-.patch
  patch -Np1 -i ../CVE-2016-5104.patch
  patch -Np1 -i ../0001-Add-new-function-to-get-the-underlying-file-descript.patch
  patch -Np1 -i ../0001-Updated-gnutls-certificate-callback-to-new-API-backw.patch
  patch -Np1 -i ../0001-idevice-Update-GnuTLS-code-to-support-iOS-10.patch
  patch -Np1 -i ../0001-userpref-GnuTLS-Fix-pairing-record-generation-and-im.patch
  sed -e 's/AC_PYTHON_DEVEL/AX_PYTHON_DEVEL/' -i m4/cython_python.m4
  autoreconf -fi
}

build() {
  mkdir build-py2
  pushd build-py2
  PYTHON=/usr/bin/python2 CYTHON=/usr/bin/cython2 ../$pkgname-$pkgver/configure --prefix=/usr --disable-openssl
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
  popd

  mkdir build-py3
  pushd build-py3
  PYTHON=/usr/bin/python CYTHON=/usr/bin/cython ../$pkgname-$pkgver/configure --prefix=/usr --disable-openssl
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  pushd build-py2
  make DESTDIR="$pkgdir" install
  popd
  pushd build-py3/cython
  make DESTDIR="$pkgdir" install
  popd
}
